
#ifndef __CONSUMER_DRIVER_H
#define __CONSUMER_DRIVER_H

#include <stdlib.h>
#include <string.h>
#include <string>
#include <stdio.h>
#include <vector>
#include <glib.h>

using namespace std;
// Required of all plug-ins
#define LOG_CONS_INIT_SUFFIX		"Init"
#define LOG_CONS_SHUTDOWN_SUFFIX	"Shutdown"
// Required of consumer plug-ins
#define LOG_CONS_PROCESS_SUFFIX		"Process"
// Required of fetch plug-ins
#define LOG_CONS_FRIENDS_SUFFIX         "Friends"
// Optional consumer plug-in interfaces
#define LOG_CONS_JUDGE_SUFFIX      	"Judge"
// Optional interface for all plug-ins
#define LOG_CONS_FLUSH_SUFFIX		"Flush"
#define LOG_CONS_NEW_SUFFIX		"Relation"

typedef bool	(*InitFunc) (const char* consumer, const char* conf);
typedef void	(*ShutdownFunc) (void);
typedef bool	(*FriendsFunc) (const char* user, GHashTable *frs);
typedef void	(*FlushFunc) (const char* consumer);

class ConsumerDriver {
public:
  ConsumerDriver();
  ConsumerDriver(const char *consumer, const string &filename, int flags = 1);
  ~ConsumerDriver();
  bool loadLibrary(int flags = 1);

  // Initialize the consumer -- called once at startup
  bool callInit(const char*  consumer, const char* conf);
  // Process a user
  void callShutdown(void); 
  // The optional entry points:
  // get friends 
  bool callFriends(const char* user, GHashTable *frs); 
 // Flush statistics to disk, if any
  void callFlush(const char*  consumer);
  // 
  // *********************************************************************
  
  bool getStatus() { return status; }
  string getError() const { return libError; };
  bool isLoaded() const { return status; }

protected:
  const void* getLibHandle() { return libHandle; }
  void unloadLibrary();

private:
  void* getFunc(const char* suffix);
  void* libHandle;
//  string file;
  string libError;
  string consName;
  string consLibrary;
  bool status;
  FriendsFunc fFunc;

};

#endif // __CONSUMER_DRIVER_H
